﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    
                    xmlns:localiz="clr-namespace:ColorPickerLib.Localized"
                    xmlns:themes="clr-namespace:ColorPickerLib.Themes"
                    xmlns:controls="clr-namespace:ColorPickerLib.Controls"
                    xmlns:numupdown="clr-namespace:ColorPickerLib"
                    xmlns:conv="clr-namespace:ColorPickerLib.Converters"
                    xmlns:behav="clr-namespace:ColorPickerLib.Behaviours"
                    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/ColorPickerLib;component/Themes/Generic/Brushes.xaml" />
        <ResourceDictionary Source="/ColorPickerLib;component/Controls/SliderRepeatButtonStyle.xaml" />
        <ResourceDictionary Source="/ColorPickerLib;component/Controls/ColorCanvasTextBoxStyle.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <conv:ColorToSolidColorBrushConverter x:Key="ColorToSolidColorBrushConverter" />
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

    <LinearGradientBrush x:Key="ColorCanvasBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Offset="0" Color="#FFffffff" />
                <GradientStop Offset="1" Color="#FFE8EBED" />
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="HorizontalSliderTrackNormalBackground" Color="#FFE7EAEA" />

    <LinearGradientBrush x:Key="HorizontalSliderTrackNormalBorder" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FFAEB1AF" Offset="0.1" />
        <GradientStop Color="White" Offset=".9" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ThumbStroke" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FFA3AEB9" Offset="0" />
        <GradientStop Color="#FF8399A9" Offset="0.375" />
        <GradientStop Color="#FF718597" Offset="0.375" />
        <GradientStop Color="#FF617584" Offset="1" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ThumbFill" StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Offset="0" Color="#FFfefefe" />
                <GradientStop Offset="0.5" Color="#FFeff1f2" />
                <GradientStop Offset="1" Color="#FFd0d6db" />
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="ThumbMouseOver" Color="#FFE5F2F6" />

    <Style x:Key="CustomThumbForSlider"
          TargetType="{x:Type Thumb}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Rectangle x:Name="_thumb"
                              Fill="{StaticResource ThumbFill}"
                              Stroke="{StaticResource ThumbStroke}"
                              Height="14"
                              Width="8"
                              RadiusX="1"
                              RadiusY="1" />
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="_thumb" Property="Rectangle.Fill" Value="{StaticResource ThumbMouseOver}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ColorCanvasSliderStyle" TargetType="{x:Type Slider}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Slider}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                           BorderThickness="{TemplateBinding BorderThickness}"
                           Background="{TemplateBinding Background}"
                           SnapsToDevicePixels="true">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TickBar x:Name="TopTick"
                                      Fill="{TemplateBinding Foreground}"
                                      Height="4"
                                      Placement="Top"
                                      Grid.Row="0"
                                      Visibility="Collapsed" />
                            <TickBar x:Name="BottomTick"
                                      Fill="{TemplateBinding Foreground}"
                                      Height="4"
                                      Placement="Bottom"
                                      Grid.Row="2"
                                      Visibility="Collapsed" />
                            <Border x:Name="TrackBackground"
                                     BorderBrush="{StaticResource HorizontalSliderTrackNormalBorder}"
                                     BorderThickness="1"
                                     Background="{StaticResource HorizontalSliderTrackNormalBackground}"
                                     CornerRadius="1"
                                     Height="4.0"
                                     Margin="5,0"
                                     Grid.Row="1"
                                     VerticalAlignment="center">
                                <Canvas Margin="-6,-1">
                                    <Rectangle x:Name="PART_SelectionRange"
                                      Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
                                      Height="4.0"
                                      Stroke="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"
                                      StrokeThickness="1.0"
                                      Visibility="Hidden" />
                                </Canvas>
                            </Border>
                            <Track x:Name="PART_Track" Grid.Row="1">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource SliderRepeatButtonStyle}" />
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource SliderRepeatButtonStyle}" />
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb" Style="{StaticResource CustomThumbForSlider}" />
                                </Track.Thumb>
                            </Track>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type controls:ColorCanvas}">
        <Setter Property="Background" Value="{DynamicResource {x:Static themes:ResourceKeys.PanelBackgroundBrushKey}}" />
        <Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlNormalBorderKey}}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ColorCanvas}">
                    <Border Background="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <Border BorderThickness="1"
                                        Margin="3"
                                        BorderBrush="DarkGray"
                                        ClipToBounds="True" Background="{StaticResource CheckerBrush}">
                                    <Canvas x:Name="PART_ColorShadingCanvas"
                                           Width="300"
                                           Height="150"
                                           HorizontalAlignment="Left"
                                           VerticalAlignment="Top">
                                        <Rectangle x:Name="ColorShadingRectangle"
                                                 Height="{Binding ElementName=PART_ColorShadingCanvas, Path=Height}"
                                                 Width="{Binding ElementName=PART_ColorShadingCanvas, Path=Width}"
                                                 Fill="{Binding SelectedColor, ElementName=PART_SpectrumSlider, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
                                        <Rectangle x:Name="WhiteGradient"
                                                 Width="{Binding ElementName=PART_ColorShadingCanvas,Path=Width}"
                                                 Height="{Binding ElementName=PART_ColorShadingCanvas,Path=Height}">
                                            <Rectangle.Fill>
                                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                                    <GradientStop Offset="0" Color="#ffffffff" />
                                                    <GradientStop Offset="1" Color="Transparent" />
                                                </LinearGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                        <Rectangle x:Name="BlackGradient"
                                                 Width="{Binding ElementName=PART_ColorShadingCanvas,Path=Width}"
                                                 Height="{Binding ElementName=PART_ColorShadingCanvas,Path=Height}">
                                            <Rectangle.Fill>
                                                <LinearGradientBrush StartPoint="0,1" EndPoint="0, 0">
                                                    <GradientStop Offset="0" Color="#ff000000" />
                                                    <GradientStop Offset="1" Color="#00000000" />
                                                </LinearGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                        <Canvas x:Name="PART_ColorShadeSelector"
                                                Width="10"
                                                Height="10"
                                                IsHitTestVisible="False">
                                            <Ellipse Width="10"
                                                      Height="10"
                                                      StrokeThickness="3"
                                                      Stroke="#FFFFFFFF"
                                                      IsHitTestVisible="False" />
                                            <Ellipse Width="10"
                                                      Height="10"
                                                      StrokeThickness="1"
                                                      Stroke="#FF000000"
                                                      IsHitTestVisible="False" />
                                        </Canvas>
                                    </Canvas>
                                </Border>

                                <Border Grid.Row="1" Margin="3">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <Border x:Name="SelectedColorBorder"
                                                  Background="{StaticResource CheckerBrush}"
                                                  MinHeight="22"
                                                  Margin="3"
                                                  BorderThickness="1"
                                                  BorderBrush="#FFC9CACA">
                                            <Rectangle x:Name="SelectedColor"
                                                        Fill="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
                                        </Border>
                                        <!-- Provide a textbox for entering complete hexadeciaml color codes -->
                                        <!-- behaviour allows only characters that conform to hexadecimal input -->
                                        <TextBox x:Name="PART_HexadecimalTextBox"
                                                   Grid.Column="1"
                                                   Margin="3"
                                                   VerticalAlignment="Center"
                                                   MaxLength="8"
                                                   Style="{StaticResource ColorCanvasTextBoxStyle}"
                                                   behav:AllowableCharactersTextBoxBehavior.RegularExpressionProperty="^[0-9|a-f|A-F]+$"
                                                 />

                                        <TextBlock Grid.Column="1"
                                                   Margin="3"
                                                   VerticalAlignment="Center"
                                                   Style="{StaticResource ColorCanvasTextBlockStyle}"
                                                   Text="#XXXXXXXXX"
                                                   Visibility="Hidden" />
                                        <!-- Size Measuring TextBlock -->
                                    </Grid>
                                </Border>

                                <Border Grid.Column="2" Grid.RowSpan="2" Margin="3">
                                    <controls:ColorSpectrumSlider x:Name="PART_SpectrumSlider" VerticalAlignment="Stretch" />
                                </Border>
                            </Grid>

                            <Border x:Name="RGBBorder"
                                    MinWidth="180"
                                    Grid.Row="1"
                                    BorderThickness="1"
                                    ClipToBounds="True"
                                     Margin="3,12,3,12">
                                <Grid>
                                    <Grid.Resources>
                                        <Style x:Key="controlInError" TargetType="numupdown:ByteUpDown">
                                            <Style.Triggers>
                                                <Trigger Property="Validation.HasError" Value="true">
                                                    <Setter Property="ToolTip"
                                                            Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                                                            Path=(Validation.Errors).CurrentItem.ErrorContent}" />
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Grid.Resources>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Grid.Row="0"
                                               Grid.Column="0"
                                               Grid.ColumnSpan="2"
                                               Text="{Binding Source={x:Static localiz:Strings.STR_RED_LABEL}, StringFormat={}{0}:}"
                                               VerticalAlignment="Center"
                                               Margin="0,6,0,0"
                                               />
                                    <Slider x:Name="PART_RSlider" Grid.Row="1" Grid.Column="0"
                                           Maximum="255"
                                           SmallChange="1"
                                           LargeChange="10"
                                           TickFrequency="1"
                                           Margin="3,6,3,6"
                                           Value="{Binding R, RelativeSource={RelativeSource TemplatedParent}}"
                                           VerticalAlignment="Center" />

                                    <numupdown:ByteUpDown Grid.Row="1" Grid.Column="1"
                                            Value="{Binding Value, ElementName=PART_RSlider}"
                                            VerticalAlignment="Center" HorizontalAlignment="Stretch"
                                            Minimum="0" Maximum="255"
                                            ParsingNumberStyle="Integer"
                                            DefaultValue="128"
                                            DisplayDefaultValueOnEmptyText="True"
                                            
                                                          
                                            Style="{StaticResource controlInError}" />
                                    <TextBlock Grid.Row="1" Grid.Column="1"
                                                VerticalAlignment="Center"
                                                Style="{StaticResource ColorCanvasTextBlockStyle}"
                                                Text="XXXX"
                                                Visibility="Hidden" />
                                    <!-- Size Measuring TextBlock -->

                                    <TextBlock Grid.Row="2"
                                               Grid.Column="0" Grid.ColumnSpan="2"
                                              Text="{Binding Source={x:Static localiz:Strings.STR_GREEN_LABEL}, StringFormat={}{0}:}"
                                              VerticalAlignment="Center"
                                              Margin="0,6,0,0"
                                               />

                                    <Slider x:Name="PART_GSlider" Grid.Row="3" Grid.Column="0"
                                           Maximum="255"
                                           SmallChange="1"
                                           LargeChange="10"
                                           TickFrequency="1"
                                           Margin="3,6,3,6"
                                           Value="{Binding G, RelativeSource={RelativeSource TemplatedParent}}"
                                           VerticalAlignment="Center" />
                                    <numupdown:ByteUpDown Grid.Row="3" Grid.Column="1"
                                            Value="{Binding Value, ElementName=PART_GSlider}"
                                            VerticalAlignment="Center"  HorizontalAlignment="Stretch"
                                            Minimum="0" Maximum="255"
                                            ParsingNumberStyle="Integer"
                                            DefaultValue="128"
                                            DisplayDefaultValueOnEmptyText="True"
                                            Style="{StaticResource controlInError}" />

                                    <TextBlock Grid.Row="4" Grid.Column="0"
                                              Text="{Binding Source={x:Static localiz:Strings.STR_BLUE_LABEL}, StringFormat={}{0}:}"
                                              VerticalAlignment="Center"
                                              Margin="0,6,0,0"
                                               />
                                    <Slider x:Name="PART_BSlider" Grid.Row="5" Grid.Column="0"
                                            Maximum="255"
                                            SmallChange="1"
                                            LargeChange="10"
                                            TickFrequency="1"
                                            Margin="3,6,3,6"
                                            Value="{Binding B, RelativeSource={RelativeSource TemplatedParent}}"
                                            VerticalAlignment="Center" />
                                    <numupdown:ByteUpDown Grid.Row="5" Grid.Column="1"
                                            Value="{Binding Value, ElementName=PART_BSlider}"
                                            VerticalAlignment="Center" HorizontalAlignment="Stretch"
                                            Minimum="0" Maximum="255"
                                            ParsingNumberStyle="Integer"
                                            DefaultValue="128"
                                            DisplayDefaultValueOnEmptyText="True"
                                            Style="{StaticResource controlInError}" />

                                    <TextBlock Grid.Row="6" Grid.Column="0"
                                              Text="{Binding Source={x:Static localiz:Strings.STR_ALPHA_LABEL}, StringFormat={}{0}:}"
                                              VerticalAlignment="Center"
                                              Visibility="{Binding Path=UsingAlphaChannel, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"
                                               Margin="0,12,0,0"
                                               />
                                    <Slider x:Name="PART_OpacitySlider" Grid.Row="7" Grid.Column="0"
                                           Maximum="255"
                                           SmallChange="1"
                                           LargeChange="10"
                                           Margin="3,6,3,6"
                                           Value="{Binding Path=A, RelativeSource={RelativeSource TemplatedParent}}"
                                           VerticalAlignment="Center"
                                           Visibility="{Binding Path=UsingAlphaChannel, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                                    <numupdown:ByteUpDown Grid.Row="7" Grid.Column="1"
                                            Value="{Binding Value, ElementName=PART_OpacitySlider}"
                                            VerticalAlignment="Center" HorizontalAlignment="Stretch"
                                            Minimum="0" Maximum="255"
                                            ParsingNumberStyle="Integer"
                                            DefaultValue="255"
                                            DisplayDefaultValueOnEmptyText="True"
                                            Style="{StaticResource controlInError}"
                                            Visibility="{Binding Path=UsingAlphaChannel, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"
                                    />
                                </Grid>
                            </Border>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                        <Trigger Property="SelectedColor" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed" TargetName="PART_ColorShadeSelector" />
                            <Setter Property="Background" Value="Transparent" TargetName="SelectedColorBorder" />
                            <Setter Property="IsEnabled" Value="False" TargetName="RGBBorder" />
                            <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" TargetName="RGBBorder" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>